/**
 * Created by meiguizhinian on 2018/7/16
 * Copyright © 2018 lixiaolong. All rights reserved.
 */

//单例/全静态/枚举
ivy.SceneDataManager = {
	getInstance: function () {
		return this;
	},

	initWithSceneID : function(sceneID) {
		this._curSceneID = sceneID;
		let sceneFileName = ivy.SceneCommonDataManager.getInstance().getSceneFileNameBySceneID(sceneID);
		this.initWithSceneFile(sceneFileName);
		return sceneFileName;
	},

	initWithSceneFile : function(name) {
		let sceneFilePath = ivy.GlobleConfig.getInstance().getSceneDataPath(name);
		let is = new ivy.InputStream(sceneFilePath);
		cc.assert(!is.empty());
		this._curSceneName = is.readStringUTF8();
		this._curSceneFlag = is.readJInt32();
		this._curSceneMapItemName = is.readStringUTF8();
		this._curSceneBuildItemName = is.readStringUTF8();
		this._curSceneMapXmlName = is.readStringUTF8();

		this._objClassCount = is.readJInt16();
		this._objDataType = [];
		this._objClassAIIDs = [];
		this._objClassAITypes = [];
		this._objClassFlags = [];
		this._objClassNames = [];

		for (let i = 0; i < this._objClassCount; ++i) {
			this._objClassAIIDs[i] = is.readJInt16();
			this._objClassAITypes[i] = is.readInt8();
			this._objClassFlags[i] = is.readInt8();
			this._objClassNames[i] = is.readStringUTF8();
		}

		this._objCount = is.readJUInt16();
		this._objDataType = [];
		this._baseInfos = [];
		this._baseInfoLengths = [];
		for (let i = 0; i < this._objCount; ++i)
		{
			let actorName = is.readStringUTF8();
			let actorNameEn = is.readStringUTF8();
			let scriptName = is.readStringUTF8();
			let dataLength = is.readJInt16();
			this._baseInfoLengths[i] = is.readJInt16();
			this._baseInfos[i] = [];
			for (let j=0; j < this._baseInfoLengths[i]; ++j) {
				this._baseInfos[i][j] = is.readJInt16();
			}
			//2016-10-9 添加对象关联数据类型
			this._objDataType[i] =is.readInt8();
		}
		let objParentCount = is.readJInt16();
	},

	getSceneObjectCount : function() {
		return this._objCount;
	},

	getSceneObjectClassCount : function() {
		return this._objClassCount;
	},

	getObjectBaseInfo : function(actorID, infoIndex) {
		if (actorID >= 0 && actorID < this._baseInfos.length) {
			if (infoIndex >= 0 && infoIndex < this._baseInfos[actorID].length)
				return this._baseInfos[actorID][infoIndex];
		}
		return 0;
	},

	getObjectExInfo : function(actorID, baseInfoLength, infoIndex) {
		if (actorID >= 0 && actorID < this._baseInfos.length) {
			let finalInfoIndex = infoIndex + baseInfoLength;
			if (finalInfoIndex >= 0 && finalInfoIndex < this._baseInfos[actorID].length)
				return this._baseInfos[actorID][finalInfoIndex];
		}
		return 0;
	},

	getObjectClassName : function(classID) {
		return this._objClassNames[classID];
	},

	getObjectClassFlag : function(classID) {
		return this._objClassFlags[classID]
	},

	getObjectClassAIType : function(classID) {
		return this._objClassAITypes[classID]
	},

	getObjectClassAIID : function(classID) {
		return this._objClassAIIDs[classID]
	},

	getObjectDataTypeByActorID : function(actorID) {
		return this._objDataType[actorID]
	},
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////private:
	_curSceneID : 0,
	_curSceneFlag : 0,
	_curSceneName : "",
	_curSceneMapItemName : "",
	_curSceneBuildItemName : "",
	_curSceneMapXmlName : "",

	_objClassCount : 0,
	_objDataType : [],
	_objClassAIIDs : [],
	_objClassAITypes : [],
	_objClassFlags : [],
	_objClassNames : [],

	_objCount : 0,
	_baseInfoLengths : [],
	_baseInfos : [],
};
